<template>
	<view style="margin-left: 5px;margin-right: 5px;margin-top: 2%;margin-bottom: 5%;">
		<text style="font-size: 40rpx;color:#00bebe">周一</text><text v-if="monday.length==0">\n 今天没有课，起飞！</text>
		<u-collapse :accordion="false" style="margin-bottom: 3%">
			<u-collapse-item :title="item.courseName" v-for="(item, index) in monday" :key="index">
				<text>时间:{{item.courseStartTime}}-{{item.courseEndTime}}&nbsp;&nbsp;地点:{{item.area.areaPosition}}{{item.area.areaFloor}}层{{item.area.areaDetail}}&nbsp;&nbsp;教师:{{item.teacherName}}&nbsp;学分:{{item.courseCredit}}</text>
			</u-collapse-item>
		</u-collapse>
		<u-gap height="8" bgColor="#e8e8e8" style="margin-bottom: 3%"></u-gap>
		<text style="font-size: 40rpx;color:#00bebe">周二</text><text v-if="tuesday.length==0">\n 今天没有课，起飞！</text>
		<u-collapse :accordion="false" style="margin-bottom: 3%">
			<u-collapse-item :title="item.courseName" v-for="(item, index) in tuesday" :key="index">
				<text>时间:{{item.courseStartTime}}-{{item.courseEndTime}}&nbsp;&nbsp;地点:{{item.area.areaPosition}}{{item.area.areaFloor}}层{{item.area.areaDetail}}&nbsp;&nbsp;教师:{{item.teacherName}}&nbsp;学分:{{item.courseCredit}}</text>
			</u-collapse-item>
		</u-collapse>
		<u-gap height="8" bgColor="#e8e8e8" style="margin-bottom: 3%"></u-gap>
		<text style="font-size: 40rpx;color:#00bebe">周三</text><text v-if="wednesday.length==0">\n 今天没有课，起飞！</text>
		<u-collapse :accordion="false" style="margin-bottom: 3%">
			<u-collapse-item :title="item.courseName" v-for="(item, index) in wednesday" :key="index">
				<text>时间:{{item.courseStartTime}}-{{item.courseEndTime}}&nbsp;&nbsp;地点:{{item.area.areaPosition}}{{item.area.areaFloor}}层{{item.area.areaDetail}}&nbsp;&nbsp;教师:{{item.teacherName}}&nbsp;学分:{{item.courseCredit}}</text>
			</u-collapse-item>
		</u-collapse>
		<u-gap height="8" bgColor="#e8e8e8" style="margin-bottom: 3%"></u-gap>
		<text style="font-size: 40rpx;color:#00bebe">周四</text><text v-if="thursday.length==0">\n 今天没有课，起飞！</text>
		<u-collapse :accordion="false" style="margin-bottom: 3%">
			<u-collapse-item :title="item.courseName" v-for="(item, index) in thursday" :key="index">
				<text>时间:{{item.courseStartTime}}-{{item.courseEndTime}}&nbsp;&nbsp;地点:{{item.area.areaPosition}}{{item.area.areaFloor}}层{{item.area.areaDetail}}&nbsp;&nbsp;教师:{{item.teacherName}}&nbsp;学分:{{item.courseCredit}}</text>

			</u-collapse-item>
		</u-collapse>
		<u-gap height="8" bgColor="#e8e8e8" style="margin-bottom: 3%"></u-gap>
		<text style="font-size: 40rpx;color:#00bebe">周五</text><text v-if="friday.length==0">\n 今天没有课，起飞！</text>
		<u-collapse :accordion="false" style="margin-bottom: 3%">
			<u-collapse-item :title="item.courseName" v-for="(item, index) in friday" :key="index">
				<text>时间:{{item.courseStartTime}}-{{item.courseEndTime}}&nbsp;&nbsp;地点:{{item.area.areaPosition}}{{item.area.areaFloor}}层{{item.area.areaDetail}}&nbsp;&nbsp;教师:{{item.teacherName}}&nbsp;学分:{{item.courseCredit}}</text>

			</u-collapse-item>
		</u-collapse>
		<u-gap height="8" bgColor="#e8e8e8" style="margin-bottom: 3%"></u-gap>
		<text style="font-size: 40rpx;color:#00bebe">周六</text><text v-if="saturday.length==0">\n 今天没有课，起飞！</text>
		<u-collapse :accordion="false" style="margin-bottom: 3%">
			<u-collapse-item :title="item.courseName" v-for="(item, index) in saturday" :key="index">
				<text>时间:{{item.courseStartTime}}-{{item.courseEndTime}}&nbsp;&nbsp;地点:{{item.area.areaPosition}}{{item.area.areaFloor}}层{{item.area.areaDetail}}&nbsp;&nbsp;教师:{{item.teacherName}}&nbsp;学分:{{item.courseCredit}}</text>

			</u-collapse-item>
		</u-collapse>
		<u-gap height="8" bgColor="#e8e8e8" style="margin-bottom: 3%"></u-gap>
		<text style="font-size: 40rpx;color:#00bebe">周日</text><text v-if="sunday.length==0">\n 今天没有课，起飞！</text>
		<u-collapse :accordion="false" style="margin-bottom: 3%">
			<u-collapse-item :title="item.courseName" v-for="(item, index) in sunday" :key="index">
				<text>时间:{{item.courseStartTime}}-{{item.courseEndTime}}&nbsp;&nbsp;地点:{{item.area.areaPosition}}{{item.area.areaFloor}}层{{item.area.areaDetail}}&nbsp;&nbsp;教师:{{item.teacherName}}&nbsp;学分:{{item.courseCredit}}</text>

			</u-collapse-item>
		</u-collapse>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				monday: [],
				tuesday: [],
				wednesday: [],
				thursday: [],
				friday: [],
				saturday: [],
				sunday: [],
			};
		},
		methods: {
			onPageTo(url) {
				uni.navigateTo({
					url: url
				})
			},
			dateData(property, type) {
				//property是你需要排序传入的时间,type为true时是升序，false为降序
				return function(a, b) {
					var value1 = a[property];
					var value2 = b[property];
					if (type) {
						// 升序
						return Date.parse("2022-10-26 " + value1) - Date.parse("2022-10-26 " + value2);
					} else {
						// 降序
						return Date.parse("2022-10-26 " + value2) - Date.parse("2022-10-26 " + value1)
					}
				}
			}
		},
		created() {
			let studentId=uni.getStorageSync("studentId");
			let classId=uni.getStorageSync("classId");
			this.$axios.get("/api/v1/student/mycourse?studentId="+studentId+"&classId="+classId).then(res => {
				let result = res.data.data;
				this.monday = result[0];
				this.tuesday = result[1].sort(this.dateData("courseStartTime", true));
				this.wednesday = result[2];
				this.thursday = result[3];
				this.friday = result[4];
				this.saturday = result[5];
				this.sunday = result[6];
			});

		}
	}
</script>

<style lang="scss">

</style>
